<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>申请认证商家列表</title>
    <link rel="stylesheet" href="__CSS__/supplies/bootstrap.min.css" />
    <link rel="stylesheet" href="__CSS__/supplies/common.css" />
    <link rel="stylesheet" href="__JS__/supplies/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <link rel="stylesheet" href="__JS__/supplies/bootstrap-table/bootstrap-table.min.css">
    <link rel="stylesheet" href="__ASSETS__/css/font-awesome.min.css" />
    <link rel="stylesheet" href="__ASSETS__/css/cyrillic.css" />
    <!--<link rel="stylesheet" href="__ASSETS__/css/ace.min.css" />-->
    <link rel="stylesheet" href="__ASSETS__/css/ace-rtl.min.css" />
    <link rel="stylesheet" href="__ASSETS__/css/ace-skins.min.css" />
    <style>
        body{
            height: 100% ;
            overflow: hidden;
            background: white;
        }
        .form-title {
            height: 40px;
            /*min-width: 60px;*/
            text-align: right;
        }
        .checkHead table .form-value input{
            height: 34px;
            width: 200px;
        }
        #user_table tr td{
            vertical-align: inherit;!important;
        }
        .my_skin .layui-layer-btn a{
            border-color: #999;!important;
            background-color: white;!important;
            color: #333;!important;
        }
        .delete_a{
            cursor: pointer;
        }
        .table-responsive{
            height:calc(100% - 90px)
        }
        .bootstrap-table{
            height:100%
        }
        .fixed-table-container{
            height:calc(100% - 60px) !important;
        }
    </style>
</head>
<body>
<div id="content">
    <!--搜索-->
    <div class="checkHead" style="padding-top: 10px;height: 90px;" >
        <table class="checkHead-table" style="/*position: absolute;right: 0px;*/">

            <tr>
            <td class="form-title">
                店铺名称：
            </td>
            <td class="form-value">
                <input v-model="searchData.name" type="text" class="search" placeholder="请输入店铺名称" />&nbsp;&nbsp;&nbsp;&nbsp;
            </td>
            <td>
                <button class="btn btn-default" v-on:click ="searchs()">
                    <i class="icon-refresh align-top bigger-125"></i>
                    查询
                </button>
                <button class="btn btn-default" v-on:click="refresh">
                    <i class="icon-reply align-top bigger-125"></i>
                    重置
                </button>
            </td>
        </tr>
        </table>
    </div>
</div>

<div class="table-responsive" style="background:white;margin-top: 0px;">
    <table class="table" id="user_table"></table>
</div>

<script rel="script" src="__JS__/supplies/jquery.min.js"></script>
<script rel="script" src="__JS__/supplies/bootstrap.min.js"></script>
<script rel="script" src="__JS__/supplies/bootstrap-table/bootstrap-table.min.js"></script>
<script rel="script" src="__JS__/supplies/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script rel="script" src="__JS__/supplies/vue.min.js"></script>
<script rel="script" src="__JS__/supplies/vue-validator.min.js"></script>
<script rel="script" src="__JS__/supplies/common.js"></script>
<script rel="script" src="__JS__/supplies/ztree/jquery.ztree.all.min.js"></script>
<script rel="script" src="__JS__/supplies/layer/layer.js"></script>
<script>
    var searchData = {};
    var setting = {
        view: {
            selectedMulti: false
        },
        async: {
            enable: true,
            url: "{:url('apishop/Index/getAreaTree')}",
            autoParam: ["name", "nameEn"],
            otherParam: { "otherParam": "zTreeAsyncTest" },
            dataFilter: filter
        },
        callback: {
            beforeClick: beforeClick,
            beforeAsync: beforeAsync,
            onAsyncError: onAsyncError,
            onAsyncSuccess: onAsyncSuccess
        }
    };

    function filter(treeId, parentNode, childNodes) {
        if (!childNodes) return null;
        for (var i = 0, l = childNodes.length; i < l; i++) {
            childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
        }
        return childNodes;
    }
    function beforeClick(treeId, treeNode) {
        if (!treeNode.isParent) {
            {
            }
        } else {
            return true;
        }
    }
    var log, className = "dark";
    function beforeAsync(treeId, treeNode) {

        className = (className === "dark" ? "" : "dark");
        showLog("[ " + getTime() + " beforeAsync ]&nbsp;&nbsp;&nbsp;&nbsp;" + ((!!treeNode && !!treeNode.name) ? treeNode.name : "root"));
        return true;
    }
    function onAsyncError(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {
        showLog("[ " + getTime() + " onAsyncError ]&nbsp;&nbsp;&nbsp;&nbsp;" + ((!!treeNode && !!treeNode.name) ? treeNode.name : "root"));
    }
    function onAsyncSuccess(event, treeId, treeNode, msg) {
        showLog("[ " + getTime() + " onAsyncSuccess ]&nbsp;&nbsp;&nbsp;&nbsp;" + ((!!treeNode && !!treeNode.name) ? treeNode.name : "root"));
    }

    function showLog(str) {
        if (!log) log = $("#log");
        log.append("<li class='" + className + "'>" + str + "</li>");
        if (log.children("li").length > 8) {
            log.get(0).removeChild(log.children("li")[0]);
        }
    }
    function getTime() {
        var now = new Date(),
                h = now.getHours(),
                m = now.getMinutes(),
                s = now.getSeconds(),
                ms = now.getMilliseconds();
        return (h + ":" + m + ":" + s + " " + ms);
    }

    function refreshNode(e) {
        var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
                type = e.data.type,
                silent = e.data.silent,
                nodes = zTree.getSelectedNodes();
        if (nodes.length == 0) {
            alert("请先选择一个父节点");
        }
        for (var i = 0, l = nodes.length; i < l; i++) {
            zTree.reAsyncChildNodes(nodes[i], type, silent);
            if (!silent) zTree.selectNode(nodes[i]);
        }
    }

    $(document).ready(function () {
        $.fn.zTree.init($("#treeDemo"), setting);

        $(".county").on("click",function(){
            $('#countyModal').modal({
                keyboard: true
            })
        })
    });
    var tableheight = document.documentElement.clientHeight - 96;
    // 用户管理
    $('#user_table').bootstrapTableEx({
        height: tableheight,
        url: '{:url("admin/Discount/discount")}',
        columns: [
            {
                checkbox: true
            }, {
                field: 'id',
                align: 'center',
                title: '序号',
                width:120
            }, {
                field: 'condition_money',
                align: 'center',
                title: '满多少'
            }, {
                field: 'relief_money',
                align: 'center',
                title: '减多少'
            },
            {
                field: 'name1',
                align: 'center',
                title: '商品名称'
            },

            {
                field: 'name2',
                align: 'center',
                title: '商铺中文名'
            },
//            {
//                field: 'start_time',
//                align: 'center',
//                title: '商铺英文名'
//            },
            {
                field: 'start_time',
                align: 'center',
                title: '开始时间'
            },{
                field: 'end_time',
                align: 'center',
                title: '结束时间'
            },
            {
                field: 'type_name',
                align: 'center',
                title: '类型'
            }, {
                field: 'condition_num',
                align: 'center',
                title: '满多少数量'
            }, {
                field: 'groom',
                align: 'center',
                title: '是否推荐'
            }, {
                title: '操作',
                align: 'center',
                width: 220,
                formatter: operateFormatter
            }
        ],
        queryParams: function (params) {
            var param = {
                search: searchData,
                pageSize: params.pageSize,
                pageNumber: params.pageNumber
            };
            return param;
        },
        responseHandler: function (res) {
            if (res.data) {
                return {
                    rows: res.data,
                    total: res.count
                };
            }
        }
    });
    // 详情按钮
    function operateFormatter(val, row, index) {
        if(row.is_groom==2){
            var divStr = "<div class='form-inline'>"
            var detailStr = "<a href='javascript:void(0);' class='detail_a' onclick='refuseAuth(1,"+row.id+")'>不推荐</a>&nbsp;&nbsp;";
            divStr += detailStr;
            divStr += "</div>";
        }else{
            var divStr = "<div class='form-inline'>"
            var detailStr = "<a href='javascript:void(0);' class='detail_a' onclick='supplierSuccess(2,"+row.id+")'>推荐</a>&nbsp;&nbsp;";
            divStr += detailStr;
            divStr += "</div>";
        }
        return divStr;
    }
    //拒绝详细
    function refuseModal(index,id){
        $('#refuseModal').modal({
            keyboard: true
        });
        vm.id = id;
    }

    function supplierSuccess(index , id ) {
        vm.successAuth(index , id);
    }
    function refuseAuth(index , id ) {
        vm.refuseAuth(index , id);
    }
    function saveCounty(){
        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        var nodes = zTree.getSelectedNodes();
        console.log(nodes);
        if(nodes.length == 0){
            alert("请选择郡");
            return false;
        }
        $(".county").val(nodes[0].name);
    }
    vm = new Vue( {
        el : "#content" ,
        data : {
            searchData : {
            } ,
            formData:{
                message : '',
            },
            id:'',
        } ,
        methods : {
            searchs : function ( index ) {
                searchData = this.searchData;
                var city = $('.county').val();
                if(city)
                {
                    searchData.city = $('.county').val();
                }
                if ( index == 1 ) {
                    $( "#user_table" ).bootstrapTable( 'refresh' );
                } else {
                    $( "#user_table" ).bootstrapTable( 'refresh' );
                }
            } ,
            //推荐
            refuseAuth : function (index , id) {
                layer.config({
                    skin:"my_skin"
                })
                layer.confirm('您确定不推荐？', {
                    btn: ['确定','取消'] //按钮
                }, function(){
                    $.ajax({
                        url : '{:url("admin/Discount/authSupplier")}',
                        type : "POST",
                        data:{'id':id, 'type':1},
                        success : function (data) {
                            layer.confirm(data.msg, {
                                time: 20000, //20s后自动关闭
                                btn: ['关闭']
                            },function () {
                                location.reload();
                            });
                        }
                    })
                });
            },
            //推荐
            successAuth : function (index , id) {
                layer.config({
                    skin:"my_skin"
                })
                layer.confirm('您确定推荐？', {
                    btn: ['确定','取消'] //按钮
                }, function(){
                    $.ajax({
                        url : '{:url("admin/Discount/authSupplier")}',
                        type : "POST",
                        data:{'id':id, 'type':2},
                        success : function (data) {
                            console.log(data);
                            layer.confirm(data.msg, {
                                time: 20000, //20s后自动关闭
                                btn: ['关闭']
                            },function () {
                                location.reload();
                            });
                        }
                    })
                });
            },
            refresh : function () {
                this.searchData = {};
            }
        } ,
    } );


</script>
</body>
</html>